<template>
  <div class="app-container">
    <div style="text-align: center;">
      <span style="font-size: 24px; color: #000000; font-weight: bold">{{ data.name }}</span>
    </div>
    <div style="margin: 40px 0 20px 0">
      <span v-html="data.description" style="font-size: 14px; color: #666666"/>
    </div>
    <div>
      <div v-for="(item, index) in questions">
        <div>
          <span style="font-size: 18px; color: #000000">{{ num[index] }}、{{ item.label }}</span>
        </div>
        <div v-for="(q, index) in item.questions" style="margin: 10px; font-size: 14px">
          <div style="margin-bottom: 5px">
            {{ index + 1 }}.{{ q.topic }}<span style="margin-left: 10px; color: orange">分值:{{ q.score }}</span>
          </div>
          <div>
            <div v-if="q.type === '1' || q.type === '2'">
              <div v-for="o in JSON.parse(q.options)" style="margin: 10px">
                {{ o.value }}.{{ o.label }}
              </div>
              <div style="color: green">
                答案：{{ q.answer }}
              </div>
            </div>
            <div v-if="q.type === '3'" style="color: green">
              答案：{{ q.answer === 'T' ? '正确' : '错误' }}
            </div>
            <div v-if="q.type === '4'" style="color: green">
              答案：
              <div style="margin: 5px 0" v-for="(item, index) in JSON.parse(q.answer)">
                第{{ index + 1 }}空：{{ item.answer }}
              </div>
            </div>
            <div v-if="q.type === '5'" style="color: green">
              答案：无
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {testPaperInfo} from "@/api/exam/testPaper";

export default {
  name: 'index',
  props: {
    id: {
      default: null,
      type: String
    }
  },
  dicts: ['exam_question_type'],
  data() {
    return {
      num: ['一', '二', '三', '四', '五'],
      data: {},
      questions: []
    }
  },
  created() {
    this.getInfo()
  },
  methods: {
    getInfo() {
      testPaperInfo(this.id, 1).then(res => {
        this.data = res.data
        this.dict.type.exam_question_type.forEach(d => {
          const questions = this.data.questions.filter(q => q.type === d.value)
          if (questions.length > 0) {
            this.questions.push({
              label: d.label,
              questions
            })
          }
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
